<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Search Bills" >
                        <f:facet name="header" >   
                            <h:panelGrid columns="1" >


                                <h:panelGrid columns="7" >
                                    <h:outputLabel value="From Date"/>
                                    <p:calendar styleClass="dateTimePicker" id="fromDate" value="#{searchController.fromDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >      
                                    </p:calendar>
                                    <h:outputLabel value="To Date"/>
                                    <p:calendar id="toDate" value="#{searchController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >                                                                              
                                    </p:calendar>
                                    <p:commandButton id="btnSearch" ajax="false" value="Search" action="#{searchController.createPaymentTable}"/>
                                    <p:commandButton id="btnSearch2" ajax="false" value="Search All" action="#{searchController.createPaymentTableAll}"/>
                                    <p:commandButton actionListener="#{searchController.createPaymentTableAll}" value="Excel" ajax="false">
                                        <pe:exporter type="xlsx" target="tblBills" fileName="opd_search_professional_payment_done"  />
                                    </p:commandButton>
                                    <p:spacer height="30"/><h:outputLabel/><h:outputLabel/><h:outputLabel/>
                                    <h:outputLabel/><h:outputLabel/> <h:outputLabel/>
                                </h:panelGrid>
                                <h:panelGrid columns="9" >
                                    <h:outputLabel value="Opd Bill No"/>
                                    <h:outputLabel value="Payment Bill No"/>
                                    <h:outputLabel value="Patient Name"/>
                                    <h:outputLabel value="Speciality"/> 
                                    <h:outputLabel value="Staff Name"/>      
                                    <h:outputLabel value="Service Name"/>  
                                    <h:outputLabel value="Charges"/>                              
                                    <h:outputLabel value="Payment Methord"/>                              
                                    <h:outputLabel value="Credit Company"/>                              
                                    <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.billNo}" />
                                    <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.insId}" />
                                    <p:inputText autocomplete="off" value="#{searchController.searchKeyword.patientName}" />
                                    <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.speciality}" />
                                    <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.staffName}" />
                                    <p:inputText autocomplete="off"  value="#{searchController.searchKeyword.itemName}" />
                                    <p:inputText autocomplete="off" value="#{searchController.searchKeyword.total}"/>
                                    <p:selectOneMenu  value="#{searchController.searchKeyword.paymentMethod}">
                                        <f:selectItem itemLabel="select Payment Methord" />
                                        <f:selectItems value="#{enumController.paymentMethods}" />
                                    </p:selectOneMenu>
                                    <p:autoComplete id="creditCompany" 
                                                    forceSelection="true"
                                                    value="#{searchController.reportKeyWord.institution}"  
                                                    completeMethod="#{creditCompanyController.completeCredit}" var="ix" 
                                                    itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 300px;">

                                    </p:autoComplete>
                                </h:panelGrid>
                            </h:panelGrid>
                        </f:facet>

                        <!--<p:defaultCommand target="btnSearch" />-->

                        <p:dataTable id="tblBills" value="#{searchController.billItems}" var="bi" rowIndexVar="i" >
                            <p:column>
                                <p:commandButton ajax="false" value="View Bill" action="payment_bill_reprint">
                                    <f:setPropertyActionListener value="#{bi.bill}" target="#{billSearch.bill}"/>
                                </p:commandButton>
                            </p:column>
                            <p:column headerText="Opd Bill No" >
                                <h:outputLabel value="#{bi.paidForBillFee.bill.insId}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Credit Company" >
                                <h:outputLabel value="#{bi.paidForBillFee.bill.creditCompany.name}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Payment Bill No" >
                                <h:outputLabel value="#{bi.bill.insId}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Payment Methord" rendered="#{searchController.searchKeyword.paymentMethod ne null}" >
                                <h:outputLabel value="#{bi.paidForBillFee.bill.paymentMethod}" ></h:outputLabel>
                            </p:column>
                            <p:column headerText="Specility" >
                                <h:outputLabel value="#{bi.paidForBillFee.staff.speciality.name}" ></h:outputLabel>
                            </p:column>    
                            <p:column headerText="Doctor" >
                                <h:outputLabel value="#{bi.paidForBillFee.staff.person.nameWithTitle}" ></h:outputLabel>

                            </p:column>                         
                            <p:column headerText="Paid at"  >
                                <h:outputLabel value="#{bi.bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{bi.bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{bi.bill.cancelled}" value="#{bi.bill.cancelledBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bi.bill.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded at " />
                                    <h:outputLabel style="color: red;" rendered="#{bi.bill.refunded}" value="#{bi.bill.refundedBill.createdAt}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>  
                            <p:column headerText="Bill at"  >
                                <h:outputLabel value="#{bi.paidForBillFee.bill.createdAt}" >
                                    <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                </h:outputLabel>
                            </p:column>  
                            <p:column headerText="Paid by" >

                                <h:outputLabel value="#{bi.bill.creater.webUserPerson.name}" >                                      
                                </h:outputLabel>
                                <br/>
                                <h:panelGroup rendered="#{bi.bill.cancelled}" >
                                    <h:outputLabel style="color: red;" value="Cancelled at " />
                                    <h:outputLabel style="color: red;" rendered="#{bi.bill.cancelled}" value="#{bi.bill.cancelledBill.creater.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                                <h:panelGroup rendered="#{bi.bill.refunded}" >
                                    <h:outputLabel style="color: red;" value="Refunded at " />
                                    <h:outputLabel style="color: red;" rendered="#{bi.bill.refunded}" value="#{bi.bill.refundedBill.creater.webUserPerson.name}" >
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>    
                            <p:column headerText="Service Name"  >
                                <h:outputLabel value="#{bi.paidForBillFee.billItem.item.name}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                            </p:column>
                            <p:column headerText="Charges" styleClass="averageNumericColumn" >
                                <h:outputLabel value="#{bi.paidForBillFee.feeValue}" >
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>

                            </p:column>

                        </p:dataTable>


                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
